#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <dbhelper.h>
#include <QTcpServer>
#include <QHostAddress>
#include "tcpsocket.h"
#include "pack.h"
#include <QVector>

QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE

class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();

    void regist(TcpSocket* client, Pack pack);
    void login(TcpSocket* client, Pack pack);
    void createRoom(TcpSocket* client, Pack pack);
    void joinRoom(TcpSocket* client, Pack pack);
    TcpSocket* findClient(QTcpSocket* C);
    QString findUser(const QString& room_id);

public slots:
    void onNewConnection();
    void onReadyRead();
    void onDisConnected();

private:
    Ui::Widget *ui;
    DbHelper* db;
    QTcpServer* server;
    QVector<TcpSocket*> tcpsocket_vector;
    int local_room_id; //房间号自增
};
#endif // WIDGET_H
